on awake from nib theObject
	set contents of text field "dataEntradaAno" of window "Criar Obra" to year of (current date)
	set contents of text field "dataEntradaMes" of window "Criar Obra" to month of (current date) as integer
	set contents of text field "dataEntradaDia" of window "Criar Obra" to day of (current date) as integer
end awake from nib


on clicked theObject
	if name of theObject is "a4" and state of theObject is equal to 1 then
		set visible of text field "a4Quant" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to true
		set visible of stepper "a4QuantStepper" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to true
		set contents of text field "a4Quant" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to 1
	else if name of theObject is "a4" and state of theObject is equal to 0 then
		set visible of text field "a4Quant" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to false
		set visible of stepper "a4QuantStepper" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to false
	else if name of theObject is "a3" and state of theObject is equal to 1 then
		set visible of text field "a3Quant" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to true
		set visible of stepper "a3QuantStepper" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to true
		set contents of text field "a3Quant" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to 1
	else if name of theObject is "a3" and state of theObject is equal to 0 then
		set visible of text field "a3Quant" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to false
		set visible of stepper "a3QuantStepper" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to false
	else if name of theObject is "scan" and state of theObject is equal to 1 then
		set visible of text field "scanQuant" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to true
		set visible of stepper "scanQuantStepper" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to true
		set contents of text field "scanQuant" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to 1
	else if name of theObject is "scan" and state of theObject is equal to 0 then
		set visible of text field "scanQuant" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to false
		set visible of stepper "scanQuantStepper" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to false
	else if name of theObject is "impressaoExterna" and state of theObject is equal to 0 then
		set visible of text field "impressaoExternaTxt" of tab view item "Impressão" of tab view "criar" of window "Criar Obra" to false
	else if name of theObject is "impressaoExterna" and state of theObject is equal to 1 then
		set visible of text field "impressaoExternaTxt" of tab view item "Impressão" of tab view "criar" of window "Criar Obra" to true
	else if name of theObject is "copiarFormato" then
		set formatoAbertoLarg to contents of text field "formatoAbertoLarg" of window "Criar Obra"
		set formatoAbertoAlt to contents of text field "formatoAbertoAlt" of window "Criar Obra"
		set contents of text field "formatoFechadoLarg" of window "Criar Obra" to formatoAbertoLarg
		set contents of text field "formatoFechadoAlt" of window "Criar Obra" to formatoAbertoAlt
	end if
end clicked

on choose menu item theObject
	if title of popup button "clienteFornecePopUp" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" is "Outros" then
		set visible of text field "clienteFornecePopUpTextField" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to true
	else
		set visible of text field "clienteFornecePopUpTextField" of tab view item "Prepress" of tab view "criar" of window "Criar Obra" to false
	end if
end choose menu item

on will open theObject
	
	tell user defaults
		set theDatabaseFinal to contents of default entry "theDatabaseFinal"
	end tell
	
	set theDatabase to "sqlite3 -column " & theDatabaseFinal & space & quote
	set numObra to "select nomeCliente from clientes ORDER BY nomeCliente ASC; "
	set nomeCliente to (do shell script theDatabase & numObra & quote)
	set popA to popup button "popClientesCriar" of window "Criar Obra"
	call method "removeAllItems" of popA
	set theNu to (number of words in nomeCliente) + 1
	set i to 1
	repeat until i = theNu
		make new menu item at the end of menu items of menu of popA with properties {title:(word i of nomeCliente), enabled:true}
		set i to i + 1
	end repeat
	
end will open
